package com.liyongjian.xhban.dal;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.liyongjian.xhban.model.Blog;

public interface BlogRepository
        extends PagingAndSortingRepository<Blog, Long>, JpaSpecificationExecutor<Blog> {

    @Query("select t from Blog t where (t.type=2 and t.userId=:userId) or (t.type=1 and t.state!=0 and (t.userId=:userId or t.lookUserIds like %:userIds%))")
    Page<Blog> pageByUserId(@Param("userId") Long userId, @Param("userIds") String userIds,
            Pageable pageable);


    @Query("select t from Blog t, AccountGroupDetail agd where t.id=agd.blogId and t.type=1 and t.state!=0 and agd.groupId=:groupId")
    Page<Blog> pageByGroupId(@Param("groupId") Long groupId, Pageable pageable);

    @Query("select t from Blog t, AccountGroupFamily agf where t.id=agf.blogId and t.type=2 and t.state!=0 and agf.groupId=:groupId")
    Page<Blog> pagejtByGroupId(@Param("groupId") Long groupId, Pageable pageable);
}
